<template>
  <header class="login-header">
    <div class="container m-top-20">
      <h1 class="logo">
        <RouterLink to="/">多倍</RouterLink>
      </h1>
      <RouterLink class="entry" to="/">
        进入网站首页
        <i class="iconfont icon-angle-right"></i>
        <i class="iconfont icon-angle-right"></i>
      </RouterLink>
    </div>
  </header>
  <div class="home_login" :style="'background: url(' + '/src/assets/Home/user_login__bgs.png' + ');'">
    <div class="login_block w1200">
      <div class="login_item">
        <div class="login_title">
          <ul>
            <li class="red">帐号登录</li>
            <li>|</li>
            <li>扫码登录</li>
          </ul>
        </div>
        <div class="login_input">
          <el-form ref="formRef" :rules="rules" :model="form">
            <el-form-item class="input_block" prop="username">
              <el-input type="text" v-model="form.username" placeholder="手机号" @keyup.enter="login" />
            </el-form-item>
            <el-form-item class="input_block" prop="password">
              <el-input type="password" v-model="form.password" placeholder="密码" show-password @keyup.enter="login" />
            </el-form-item>
          </el-form>
        </div>

        <div class="login_btn" @click="login">登 录</div>

        <div class="login_btn_b">
          <router-link to="/home/register">注册</router-link>
          |
          <router-link to="/home/forget_password">忘记密码？</router-link>
        </div>

        <el-divider>其他登录方式</el-divider>
        <div class="other_login_block" @click="wechatLogin()">
          <img width="35" :src="'/src/assets/Home/wechat.png'" alt="" />
          <p>微信登录</p>
        </div>
      </div>
    </div>
  </div>
  <footer class="login-footer">
    <div class="container">
      <p>
        <a href="javascript:;">关于我们</a>
        <a href="javascript:;">帮助中心</a>
        <a href="javascript:;">售后服务</a>
        <a href="javascript:;">配送与验收</a>
        <a href="javascript:;">商务合作</a>
        <a href="javascript:;">搜索推荐</a>
        <a href="javascript:;">友情链接</a>
      </p>
      <p>CopyRight &copy; 多倍</p>
    </div>
  </footer>
</template>
<script setup lang="ts">
import { useRouter, useRoute } from 'vue-router';
import { useUserStore } from '@/store/modules/user';

const userStore = useUserStore();
const formRef = ref();
const router = useRouter();
const route = useRoute();
const initFormData: any = {
  username: '15882998333',
  password: '123456'
};
const data = reactive<any>({
  form: { ...initFormData },
  rules: {
    username: [
      { required: true, message: '手机号必填', trigger: 'blur' },
      { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
    ],
    password: [
      { required: true, message: '密码必填', trigger: 'blur' },
      { min: 6, max: 25, message: '长度在 6 到 25 个字符', trigger: 'blur' },
      {
        // pattern: /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,30}$/,
        // message: '密码为数字，小写字母，大写字母，特殊符号 至少包含三种，长度为8-30位'
      }
    ]
  }
});
const { form, rules } = toRefs(data);

/*登录*/
function login() {
  formRef.value.validate(async (valid: boolean) => {
    if (valid) {
      await userStore.login(form.value).then(() => {
        let redirect: any = route.query.redirect;
        router.replace({ path: redirect || '/' });
      });
    }
  });
}

const wechatLogin = () => {};
</script>
<style scoped lang="scss">
.login_block {
  text-align: right;

  .login_btn_b {
    text-align: right;
    font-size: 12px;
    margin-top: 15px;
    margin-bottom: 40px;

    a {
      margin: 0 8px;
      color: #999;
    }
  }

  .other_login_block {
    cursor: pointer;
    text-align: center;
    line-height: 30px;

    i {
      font-size: 30px;
    }
  }

  .login_item {
    width: 400px;
    background: #fff;
    height: 450px;
    float: right;
    box-sizing: border-box;
    padding: 40px;
    margin-top: 50px;
    text-align: left;

    .login_btn {
      cursor: pointer;
      color: #fff;
      background: #ca151e;
      line-height: 35px;
      width: 100%;
      text-align: center;
      font-size: 16px;
    }

    .login_input {
      margin-top: 30px;

      .input_block {
        margin: 15px auto;
        width: 320px;

        input {
          width: 100%;
          border: 1px solid #e1e1e1;
          height: 35px;
          text-indent: 6px;
          outline: none;
        }
      }
    }

    .login_title {
      ul {
        margin-left: 55px;

        &:after {
          content: '';
          display: block;
          clear: both;
        }
      }

      ul li {
        cursor: pointer;
        float: left;
        margin-right: 20px;
        font-size: 20px;

        &.red {
          color: #ca151e;
        }

        &:hover {
          color: #ca151e;
        }
      }
    }
  }
}

.home_login {
  height: 550px;
}

.login-header {
  background: #fff;
  border-bottom: 1px solid #e4e4e4;

  .container {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
  }

  .logo {
    width: 200px;

    a {
      display: block;
      height: 132px;
      width: 100%;
      text-indent: -9999px;
      background: url('@/assets/images/logo.png') no-repeat center 18px / contain;
    }
  }

  .sub {
    flex: 1;
    font-size: 24px;
    font-weight: normal;
    margin-bottom: 38px;
    margin-left: 20px;
    color: #666;
  }

  .entry {
    width: 120px;
    margin-bottom: 38px;
    font-size: 16px;

    i {
      font-size: 14px;
      color: $xtxColor;
      letter-spacing: -5px;
    }
  }
}

.login-section {
  background: url('@/assets/images/login-bg.png') no-repeat center / cover;
  height: 488px;
  position: relative;

  .wrapper {
    width: 380px;
    background: #fff;
    position: absolute;
    left: 50%;
    top: 54px;
    transform: translate3d(100px, 0, 0);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
  }
}

.login-footer {
  padding: 30px 0 50px;
  background: #fff;

  p {
    text-align: center;
    color: #999;
    padding-top: 20px;

    a {
      line-height: 1;
      padding: 0 10px;
      color: #999;
      display: inline-block;

      ~ a {
        border-left: 1px solid #ccc;
      }
    }
  }
}

.subBtn {
  background: $xtxColor;
  width: 100%;
  color: #fff;
}
</style>
